package com.zl.gmadmin.configuration;

import com.zl.gmadmin.common.ApiResponse;
import com.zl.gmadmin.exception.BaseException;
import org.activiti.engine.ActivitiException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: ZhangLiang
 * @Date: 2021/09/10/11:05
 * @Description:
 */
@RestControllerAdvice
public class UnitExceptionHandler {
    @ExceptionHandler(ActivitiException.class)
    public ResponseEntity<ApiResponse> activitiException(ActivitiException e) {
        return buildResponseEntity(new BaseException(e.getMessage()));
    }

    /**
     * 统一返回异常
     */
    private ResponseEntity<ApiResponse> buildResponseEntity(BaseException e) {
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ApiResponse.ofException(e));
    }

}
